package com.aizuda.boot.modules.auth.controller;

import com.aizuda.boot.config.properties.FeiShuConfigProperties;
import com.aizuda.boot.modules.auth.service.IAuthService;
import com.aizuda.core.api.ApiAssert;
import com.baomidou.kisso.annotation.LoginIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author hjw
 * @description 租户管理Controller
 * @date 2025年07月05日 10:39
 */
@Tag(name = "租户管理")
@RestController
@AllArgsConstructor
@RequestMapping("/auth/tenant")
public class TenantController {
    @Resource
    private FeiShuConfigProperties feiShuConfigProperties;
    @Resource
    private IAuthService   authService;

    @Operation(summary = "飞书租户列表")
    @LoginIgnore
    @GetMapping("/list")
    public List<FeiShuConfigProperties.FeiShuAppConfig> list() {
        ApiAssert.isEmpty(feiShuConfigProperties.getApps(), "请先配置飞书应用");
        return feiShuConfigProperties.getApps().values().stream().toList();
    }

    @Operation(summary = "切换系统租户")
    @PutMapping("change/{targetSysTenantKey}")
    public Map<String, Object> changeSysTenant(
            @Parameter(description = "目标系统租户tenantKey")
            @PathVariable String targetSysTenantKey){
        return authService.changeSysTenant(targetSysTenantKey);
    }

}
